package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.MyFabulous;
import cn.wolfcode.trip.base.query.MyFabulousQueryObject;
import cn.wolfcode.trip.base.service.IMyFabulousService;
import cn.wolfcode.trip.base.util.JSONResult;
import cn.wolfcode.trip.base.util.UserContext;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;


@RestController
@RequestMapping("/myFabulous")
public class FabulousController {
    @Autowired
    private IMyFabulousService fabulousService;

    /**
     * 查询攻略、游记，日报详细点赞情况
     * @param qo
     * @return
     */
    @GetMapping
    public PageInfo ListFollowAndFansById(MyFabulousQueryObject qo) {
        PageInfo query = fabulousService.query(qo);
        return fabulousService.query(qo);
    }

    /**
     * 查询是否点赞
     * @param fabulouId
     * @return
     */
    @PutMapping("/{fabulouId}")
    public JSONResult addFabulous(@PathVariable Long fabulouId) {
        JSONResult result = new JSONResult();
        fabulousService.changeState(fabulouId);
        return result;
    }

    /**
     * 保存点赞
     * @return
     */
    @PostMapping
    public JSONResult save(MyFabulous mf) {
        mf.setState(true);
        mf.setUser(UserContext.getCurrentUser());
        mf.setCreateTime(new Date());
        JSONResult result = new JSONResult();
        fabulousService.save(mf);
        return result;
    }

}
